abstract class VisualComponent {
    draw() {

    }
    resize() {

    }
}

abstract class Decorator extends VisualComponent {
    declare private _component: VisualComponent
    constructor(vc: VisualComponent) {
        super()
        this._component = vc
    }
    draw(): void {
        this._component.draw()
    }
    resize(): void {
        this._component.resize()
    }
}
class BorderDecorator extends Decorator {
    declare private _width: number
    constructor(vc: VisualComponent, bordWidth: number) {
        super(vc)
        this._width = bordWidth
    }
    private drawBorder(bordWidth: number) {
        console.log('画边框' + bordWidth + '宽度');
    }
    draw(): void {
        super.draw()
        this.drawBorder(this._width)
    }
}
class ScrollDecorator extends Decorator {
    constructor(vc: VisualComponent) {
        super(vc)
    }
    private drawScroll() {
        console.log('画滚动条');
    }
    draw(): void {
        super.draw()
        this.drawScroll()
    }
}
//假定的TextView
export class TextView extends VisualComponent {
    declare name: string
    constructor(name: string) {
        super()
        this.name = name
    }
    draw() {
        console.log(this.name);
    }
}
//假定的Window类
class Window {
    setContent(vc: VisualComponent) {
        vc.draw()
    }
}
const tv = new TextView('我是文本')
// tv.show()
const borderDecorator = new BorderDecorator(tv, 30)
const scrollDecorator = new ScrollDecorator(borderDecorator)

const window = new Window()
window.setContent(tv)//只是画文本
window.setContent(borderDecorator)//画带边框的
window.setContent(scrollDecorator)//画带边框的和滚动条的
